/*
 * @Description:
 * @Author: cgt
 * @Date: 2021-11-04 14:58:35
 * @LastEditors: askmewhat
 * @LastEditTime: 2022-04-12 10:40:19
 */
import { getSblxBySbzlx } from '../../../../../mapUtils/SblxUtil';
import { projectLngLatToWebMercator } from '../../../../../mapUtils/CoordinateUtil';
import IpmsPoint from '../IpmsPoint';
import RuleResult from '../vo/RuleResult';

/**
 * power symbol station main interface
 */
class PmsZsbyq extends IpmsPoint {
  constructor(_tool) {
    super(_tool);
    this.drawtype = 'pms_zsbyq';
    this.defaultIcon = '4020050';
    this.defaultName = '柱上变压器';
  }

  start(option) {
    return super.start(option);
  }

  getGeometry() {
    return turf.lineString([
      this.geometry.coordinates,
      this.geometry.coordinates
    ]).geometry;
  }

  /**
     * 获取当前绘制设备信息
     * @override
     */
  async getTargetDevice() {
    let coordinates = projectLngLatToWebMercator(this.geometry.coordinates);
    let startDevice = this.getStartDevice();
    var splitInfo = this.getSplitInfo();
    let data = {
      ...this.option,
      dydj: startDevice ? startDevice.dydj : this.option.dydj, // 取捕捉线路的电压等级
      shape: this.getGeometryWkt(this.geometry),
      coordinates: coordinates,
      startDevice: startDevice,
      ...splitInfo
    };
    return data;
  }

  async _ruleJudgePoint(index, snap) {
    let layer = snap.layer;
    if (!layer) {
      return new RuleResult(false, index, '未捕捉到设备');
    }
    if (getSblxBySbzlx(layer.properties.sbzlx) === 101000) {
      return new RuleResult(true, index, 'success');
    }
    return new RuleResult(false, index, '只能捕捉导线');

  }
}

export default PmsZsbyq;
